import org.apache.spark.SparkConf;
import org.apache.spark.sql.SparkSession;

public class test {
    public static void main(String[] args) {
        SparkConf sparkConf = new SparkConf().setAppName("test").setMaster("local[*]");

        SparkSession sparkSession = SparkSession.builder().config(sparkConf).enableHiveSupport().getOrCreate();

        sparkSession.sql("use user_profile220718");

        sparkSession.sql("insert into test select * from (\n" +
                "                  select uid, cast(tag_value as string) as tag_value, 'tg_person_base_agegroup' as tag_code\n" +
                "                  from tg_person_base_agegroup\n" +
                "                  union\n" +
                "                  select uid, cast(tag_value as string) as tag_value, 'tg_person_base_gender' as tag_code\n" +
                "                  from tg_person_base_gender\n" +
                "              ) pivot (max(tag_value) as tag_value for tag_code in ('tg_person_base_agegroup','tg_person_base_gender'))");
    }
}
